#!/bin/bash
# MES系统启动脚本

echo "=== 启动MES系统 ==="
echo "当前时间: $(date)"

# 切换到项目目录
cd /home/ubuntu/zlymes/mesmaster

# 杀死现有进程
echo "清理现有进程..."
pkill -f "python manage.py runserver"

# 等待进程结束
sleep 2

# 启动基础MES服务
echo "启动基础MES服务 (端口8004)..."
python manage.py runserver 0.0.0.0:8004 --settings=settings_mes_basic > /tmp/mes_8004.log 2>&1 &
MES_BASIC_PID=$!
echo "基础MES服务启动，PID: $MES_BASIC_PID"

# 启动完整MES服务
echo "启动完整MES服务 (端口8005)..."
python manage.py runserver 0.0.0.0:8005 --settings=settings_full_mes > /tmp/mes_8005.log 2>&1 &
MES_FULL_PID=$!
echo "完整MES服务启动，PID: $MES_FULL_PID"

# 启动Django管理服务
echo "启动Django管理服务 (端口8006)..."
python manage.py runserver 0.0.0.0:8006 --settings=settings_django_with_mes > /tmp/mes_8006.log 2>&1 &
MES_ADMIN_PID=$!
echo "Django管理服务启动，PID: $MES_ADMIN_PID"

# 等待服务启动
echo "等待服务启动..."
sleep 5

# 检查服务状态
echo "检查服务状态..."
ps aux | grep "python manage.py runserver"

echo ""
echo "=== 服务启动完成 ==="
echo "基础MES服务: http://175.27.138.86:8004/admin/"
echo "完整MES服务: http://175.27.138.86:8005/admin/"
echo "Django管理: http://175.27.138.86:8006/admin/"
echo ""
echo "管理员账户:"
echo "用户名: admin"
echo "密码: admin123"
echo ""
echo "查看日志:"
echo "tail -f /tmp/mes_8004.log"
echo "tail -f /tmp/mes_8005.log"
echo "tail -f /tmp/mes_8006.log"
echo ""
echo "停止服务:"
echo "pkill -f 'python manage.py runserver'" 